﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Controllers;
using QLBH.Models;

namespace QLBH.Modules
{
    public partial class ucUnits : UserControl
    {
        private UnitsController controller;
        public ucUnits()
        {
            InitializeComponent();
            this.dgvUnits.AutoGenerateColumns = false;
            controller = new UnitsController(this);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            controller.Add();
        }

        private void ucUnits_Load(object sender, EventArgs e)
        {
            controller.LoadData();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            controller.Edit();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            controller.Delete();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            controller.LoadData();
        }
        public void DisplayData(List<Models.UnitsModel> data)
        {
            this.dgvUnits.DataSource = data;
        }


        public UnitsModel getCurrentSelectedItem()
        {
            if (dgvUnits.SelectedRows.Count > 0)
            {
                return dgvUnits.SelectedRows[0].DataBoundItem as UnitsModel;
            }
            return null;
        }
    }
}
